package com.itheima.game;

import java.util.ArrayList;
import java.util.Collections;

public class PlayGame {
    //1.准备扑克牌
    //创建牌盒
    static ArrayList<String> list = new ArrayList<>();

    //创建静态数据
    static {
        //牌的花色
        String[] colors = {"♠", "♥", "♣", "♦"};
        //牌的数字
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        //把扑克按不同的花色装进牌盒
        for (String color : colors) {//花色
            for (String number : numbers) {//数字
                list.add(color + number);
            }
        }

        //大小王
        list.add("大王");
        list.add("小王");

    }


    public PlayGame() {
        //2.洗牌
        Collections.shuffle(list);

        System.out.println(list);
        //3.发牌
        //创建4个集合 分别记录玩家的牌和底牌
        ArrayList<String> landlord = new ArrayList<>();//底牌
        ArrayList<String> player1 = new ArrayList<>();//玩家1
        ArrayList<String> player2 = new ArrayList<>();//玩家2
        ArrayList<String> player3 = new ArrayList<>();//玩家3


        for (int i = 0; i < list.size(); i++) {
            //前三张地主牌
            if (i < 3) {
                landlord.add(list.get(i));
            }else if (i % 3 == 1){
                player1.add(list.get(i));
            }else if (i % 3 == 2){
                player2.add(list.get(i));
            }else {
                player3.add(list.get(i));
            }
        }

        //4.看牌
        lockPoker(landlord,"底牌");
        lockPoker(player1,"玩家1");
        lockPoker(player2,"玩家2");
        lockPoker(player3,"玩家3");
    }

    /**
     *
     * @param list  玩家的派克
     * @param name 玩家名称
     */
    public static void lockPoker(ArrayList<String> list,String name){
        System.out.print(name + ": ");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + ", ");
        }
        System.out.println();
    }
}
